#define CHECK_TOP(index, row, col)   (((index) >= (col)) !=0)
#define CHECK_LEFT(index, row, col)  ((index)%(col) != 0)
#define CHECK_RIGHT(index, row, col)     (((index + 1) % (col)) != 0)
#define CHECK_BOTTOM(index, row, col)   ((((index) / (col)) + 1) != (row))
#define CHECK_TOP_LEFT(index, row, col) \
    CHECK_TOP(index, row, col) && CHECK_LEFT(index, row, col)
#define CHECK_TOP_RIGHT(index, row, col) \
    CHECK_TOP(index, row, col) && CHECK_RIGHT(index, row, col)
#define CHECK_BOTTOM_LEFT(index, row, col) \
    CHECK_BOTTOM(index, row, col) && CHECK_LEFT(index, row, col)
#define CHECK_BOTTOM_RIGHT(index, row, col) \
    CHECK_BOTTOM(index, row, col) && CHECK_RIGHT(index, row, col)

#ifdef SET
#undef SET
#endif
#define SET(var)\
    arival |= (CHECK_##var(index, row, col)) << var
